package com.mjlf.mjatis.core;

import com.mjlf.mjatis.config.Configuration;

import java.io.IOException;
import java.io.InputStream;

/**
 * @ClassName AbstractSqlSessionFactory
 * @Author mjlft
 * @Date 2020/5/26 23:10
 * @Version 1.0
 * @Description TODO
 */
public abstract class AbstractSqlSessionFactory implements SqlSessionFactory{

    public SqlSession buildSqlSession(InputStream inputStream) throws IOException {
        Configuration configuration = parseConfiguration(inputStream);
        return buildSqlSession(configuration);
    }



    public SqlSession buildSqlSession(String basePath) {
        Configuration configuration = parseConfiguration(basePath);
        return buildSqlSession(configuration);
    }

    public SqlSession buildSqlSession(InputStream inputStream, String basePath) {
        Configuration configuration = parseConfiguration(basePath, inputStream);
        return buildSqlSession(configuration);
    }

    /**
     * 从InputStream中解析出Configuration
     * @param inputStream
     * @return
     */
    public abstract Configuration parseConfiguration(InputStream inputStream) throws IOException;

    /**
     * 从注解配置类中解析出Configuration信息
     * @param basePath
     * @return
     */
    public abstract Configuration parseConfiguration(String basePath);

    /**
     * 混合模式拿取配置类信息
     * @param basePaht
     * @param inputStream
     * @return
     */
    public abstract Configuration parseConfiguration(String basePaht, InputStream inputStream);
}
